﻿using System;
using System.Collections.Generic;
using System.Text;
using Fan.Dongping.Ali.Common.Bean;
using Fan.Dongping.Ali.DataAccess;
using System.Data;
using Fan.Dongping.Common.DBMeta;

namespace Fan.Dongping.Ali.BusinessRules
{
    public class NoteBiz
    {
        static NoteBiz notebiz;

        public static NoteBiz Instance
        {
            get
            {
                if (notebiz == null)
                {
                    notebiz = new NoteBiz();
                }
                return NoteBiz.notebiz;

            }

        }

        public List<NoteSummary> GetUserNotes(string userId)
        {
            DataTable dt = NoteDA.Instance.GetNotes(userId);

            List<NoteSummary> ll = new List<NoteSummary>();
            foreach (DataRow item in dt.Rows)
            {
                NoteSummary lc = new NoteSummary();
                lc.Topic = item[NoteMeta.TopicField] as string;

                object o = item[NoteMeta.CreateTimeField];
                if ((o is DBNull) == false)
                {
                    lc.CreateTime = (DateTime)o;
                }

                o = item[NoteMeta.UpdateTimeField];
                if ((o is DBNull) == false)
                {
                    lc.UpdateTime = (DateTime)o;
                }


                o = item[NoteMeta.CategaryField];
                if ((o is DBNull))
                {
                    lc.Category = null;
                }
                else
                {
                    lc.Category = o.ToString();
                }

                ll.Add(lc);
            }
            return ll;
        }

    }
}
